package com.txunda.zhuohired.adapter.user.home;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.lidroid.xutils.ViewUtils;
import com.lidroid.xutils.view.annotation.ViewInject;
import com.txunda.zhuohired.R;
import com.txunda.zhuohired.bean.search.CommodityBean;

import java.util.List;

/**
 * 创建人： Txd_Cjh
 * 创建时间： 2018/2/27 16:16
 * 功能描述：搜索历史adapter
 * 联系方式：jiahuanchen@126.com
 */

public class SearchHistoryAdapter extends BaseAdapter {
    private Context context;
    private ViewHolder holder;
    private List<CommodityBean> historyList;

    public SearchHistoryAdapter(Context context, List<CommodityBean> historyList) {
        this.context = context;
        this.historyList = historyList;
    }

    @Override
    public int getCount() {
        return historyList.size();
    }

    @Override
    public Object getItem(int i) {
        return historyList.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        if (view == null) {
            view = LayoutInflater.from(context).inflate(R.layout.item_search_history, null);
            holder = new ViewHolder();
            view.setTag(holder);
            ViewUtils.inject(holder, view);
        } else {
            holder = (ViewHolder) view.getTag();
        }
        holder.tv_item_search_history.setText(historyList.get(i).getCommodityName().toString());
        return view;
    }

    class ViewHolder {
        @ViewInject(R.id.tv_item_search_history)
        private TextView tv_item_search_history;
    }
}
